package engine.gui.elements;

import engine.gui.Component;
import engine.gui.GUIStyle;

public class Label extends Component{

	private String text;
	private boolean border;
	private boolean alignCenter;
	
	public Label() {
	}
	
	public Label(String text) {
		this();
		this.text = text;
	}
	
	public Label(String text, int posX, int posY, int width, int height) {
		this(text);
		setPosX(posX);
		setPosY(posY);
		setWidth(width);
		setHeight(height);
	}
	
	public Label(int posX, int posY, int width, int height) {
		this();
		setPosX(posX);
		setPosY(posY);
		setWidth(width);
		setHeight(height);
	}
	
	@Override
	public void render(int x, int y, int width, int height) {
		if(text != null) {
			GUIStyle style = getCurrentStyle();
			
			float h = style.getFont().getHeight();
			float w = style.getFont().getWidth(text);
			
			getWindowManager().getGuiShader().sendUniform4f("color", style.getLabelColor());
			
			if(alignCenter) {
				style.getFont().draw(text, x + getPosX() + (getWidth() - w) / 2, y + getPosY() + (h + getHeight()) / 2);
			} else {
				style.getFont().draw(text, x + getPosX() + 2, y + getPosY() + (h + getHeight()) / 2);
			}
		}
	}
	
	@Override
	public void reset() {
		//do nothing
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public boolean isBorder() {
		return border;
	}

	public void setBorder(boolean border) {
		this.border = border;
	}

	public boolean isAlignCenter() {
		return alignCenter;
	}

	public void setAlignCenter(boolean center) {
		this.alignCenter = center;
	}
}
